<% title t("views.credits.meta.title") %>

<div class="credits-container">
  <% if flash[:notice].present? %>
    <div class="notice" id="notice">
      <%= flash[:notice] %>
    </div>
  <% end %>

  <div class="existing-credits">
    <div class="existing-credits-status"><%= t("views.credits.status.user", count: @user_unspent_credits_count) %></div>
    <a href="<%= purchase_credits_path %>" data-no-instant><%= t("views.credits.purchase") %></a>

    <%= render "ledger", items: @ledger[["User", current_user.id]] %>
  </div>

  <% if @organizations.present? %>
    <% @organizations.find_each do |org| %>
      <div class="existing-credits">
        <div class="existing-credits-status">
          <%= t("views.credits.status.org_html", name: org.name, num: tag.span(org.unspent_credits_count, id: "org-credits-number"), count: org.unspent_credits_count) %></span>
        </div>
        <a id="org-credits-purchase-link" href="<%= purchase_credits_path(organization_id: org.id) %>" data-no-instant>
          <%= t("views.credits.purchase") %>
        </a>

        <%= render "ledger", items: @ledger[["Organization", org.id]] %>
      </div>
    <% end %>
  <% end %>
</div>
